package com.noob.susu.excel.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * 错误码
 *
 * @author shupeng_liao
 * @date 2019/12/10 14:11
 **/
@AllArgsConstructor
@Getter
public enum ErrorCodeEnum implements BaseEnum {


    /**
     * CELL_VALUE_NULL
     */
    CELL_VALUE_NULL("CELL_VALUE_NULL", "非空字段为空"),

    /**
     * NOT_SUPPORT
     */
    NOT_SUPPORT("NOT_SUPPORT", "暂不不支持的文件类型"),

    /**
     * OBJECT_INIT_EXCEPTION
     */
    OBJECT_INIT_EXCEPTION("OBJECT_INIT_EXCEPTION", "对象实例化异常,请检查无参构造方法是否存在!"),

    /**
     * OBJECT_SET_EXCEPTION
     */
    OBJECT_SET_EXCEPTION("OBJECT_SET_EXCEPTION", "类:{0},字段:{1},set对应值异常,请检查方法!"),

    /**
     * ENUM_CONVERTER_ERROR
     */
    ENUM_CONVERTER_ERROR("ENUM_CONVERTER_ERROR", "枚举转换异常,请校验对应的转换方法!"),

    /**
     * FIELD_VALUE_NULL_ERROR
     */
    FIELD_VALUE_NULL_ERROR("FIELD_VALUE_NULL_ERROR", "字段值null异常,请检查对应的数据!"),
    ;

    private String code;

    private String msg;

    @Override
    public String getDescByCode(String code) {
        ErrorCodeEnum[] values = ErrorCodeEnum.values();
        for (int i = 0; i < values.length; i++) {
            ErrorCodeEnum value = values[i];
            if (StringUtils.equals(value.getCode(), code)) {
                return value.getMsg();
            }
        }
        return null;
    }
}
